package cn.cbsd.base

import cn.zhaosunny.soap.*
import cn.zhaosunny.soap.exception.SoapException
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import org.junit.Test
import java.lang.Exception
import java.net.InetSocketAddress
import java.net.Proxy

/**
 *
 * @author zhaoyang 2021/12/1
 */

class ExampleUnitTest {


    @Test
    fun testSoap() {
        val builder = OkHttpClient().newBuilder()
            .addInterceptor(SoapLogInterceptor())
        //代理服务器的IP和端口号
//        builder.proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress("127.0.0.1", 8888)));

        val loginService = Soap.SoapBuilder()
            .setBaseUrl("http://192.168.11.23:8664/")
            .setOkhttpClient(builder.build())
            .setInterceptor(object : ISoapInterceptor {
                override fun log(
                    nameSpace: String,
                    methodName: String,
                    endPoint: String,
                    params: LinkedHashMap<String, Any>,
                    response: String,
                ) {
                    println("++++++=" + response)
                }
            })
            .setErrorVerify(object : IErrorStateService {

                override fun isError(result: String): Boolean {
                    return result.startsWith("err-")
                }

                override fun getErrorInfo(result: String): String {
                    return result
                }

            })
            .setIsNewJdk8(true)
            .build().create(ILoginService::class.java)
        runBlocking {
            try {
                val a = loginService.login("123", "888888", "1")
                a?.let {
                    println("-----" + a)
                    val qiujiChaxun = loginService.qiujiChaxun(a.compNo, "0", "100")
                    println(qiujiChaxun)
                }

            } catch (e: Exception) {
                println("####" + e.javaClass.name)
            }
        }

    }
}
